package com.bra.ui.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.bra.R;
import com.bra.ui.base.BaseActivity;
import com.bra.utils.CommonUtils;
import com.bra.utils.DataCleanManager;
import com.bra.utils.ToastUtil;

/**
 * 设置界面
 * 
 * @author lenovo
 *
 */
public class SetActivity extends BaseActivity {
	private ImageView activity_back;
	private TextView activity_title, shezhi_banben;
	private ToggleButton toggle_tb_music, toggle_tb_zhendong;
	private String banben;
	private RelativeLayout sz__clearcache;

	@Override
	protected View onCreateView(LayoutInflater inflater,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return inflater.inflate(R.layout.activity_set, null);
	}

	@Override
	protected void onViewCreated(Bundle savedInstanceState) {
		activity_title = (TextView) findViewById(R.id.activity_title);
		activity_back = (ImageView) findViewById(R.id.activity_back);
		activity_title.setText("设置");
		toggle_tb_music = (ToggleButton) findViewById(R.id.toggle_tb_music);
		toggle_tb_zhendong = (ToggleButton) findViewById(R.id.toggle_tb_zhendong);
		shezhi_banben = (TextView) findViewById(R.id.shezhi_banben);
		banben = CommonUtils.getVersionName(this);
		shezhi_banben.setText("版本" + banben + "V");
		sz__clearcache = (RelativeLayout) findViewById(R.id.sz__clearcache);
	}

	@Override
	protected void setListener() {
		activity_back.setOnClickListener(click);
		toggle_tb_music.setOnClickListener(click);
		toggle_tb_zhendong.setOnClickListener(click);
		sz__clearcache.setOnClickListener(click);
	}

	private String cache;
	private View.OnClickListener click = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.activity_back:
				finish();
				break;
			case R.id.toggle_tb_music:
				if (toggle_tb_music.isChecked()) {
					showToast("消息提示音已经打开");
				} else {
					showToast("消息提示音已经关闭");
				}
				break;
			case R.id.toggle_tb_zhendong:
				if (toggle_tb_zhendong.isChecked()) {
					showToast("震动已经打开");
				} else {
					showToast("震动已经关闭");
				}
				break;
			case R.id.sz__clearcache:
				try {
					cache = DataCleanManager.getTotalCacheSize(getApplicationContext());
					if (cache.contains("0")) {
						ToastUtil.showToast(SetActivity.this, "缓存已经清理完，没有缓存了"+cache);
					} else {
						ToastUtil
								.showToast(SetActivity.this, "清除缓存" + cache);
						DataCleanManager.clearAllCache(SetActivity.this);
					}

				} catch (Exception e) {
					e.printStackTrace();
				}
				break;
			default:
				break;
			}

		}
	};
}